from get_info import GetGoods
import tkinter as tk
from tkinter import *


class UIMAIN:

    select_path: StringVar = ""

    def create_UI(self):
        # 创建窗口
        win = Tk()
        # 设置窗口标题
        win.title('一键采集')

        # 获取屏幕尺寸计算参数，使窗口显示再屏幕中央
        screen_width = win.winfo_screenwidth()
        screen_height = win.winfo_screenheight()
        width = 310
        height = 220
        # window_size = '%dx%d+%d+%d' % (width, height, (screen_width-width)/2, (screen_height-height)/2)
        # round去掉小数
        window_size = f'{width}x{height}+{round((screen_width-width)/2)}+{round((screen_height-height)/2)}'

        # 设置窗口宽度和高度
        win.geometry(window_size)

        Label(text='账号:').place(x=60, y=10)
        uname = Entry(win)
        uname.place(x=100, y=10)
        self.uname = uname

        Label(text='密码:').place(x=60, y=40)
        upwd = Entry(win, show='*')
        upwd.place(x=100, y=40)
        self.upwd = upwd

        Label(text='关键词:').place(x=50, y=70)
        key = Entry(win)
        key.place(x=100, y=70)
        self.key = key

        Label(text='页数:').place(x=60, y=100)
        pageSize = Entry(win)
        pageSize.place(x=100, y=100)
        self.pageSize = pageSize

        Label(text='筛选条件:').place(x=40, y=130)
        condition = Entry(win)
        condition.place(x=100, y=130)
        self.condition = condition

        Button(text='开始', command=self.collect).place(x=120, y=180, width=50)

        win.mainloop()

    def collect(self):
        GetGoods(self.uname.get(), self.upwd.get(),
                 self.key.get(), int(self.pageSize.get()),
                 self.condition.get()).get_goods_data()

    def chooseDir(self):
        path_ = tk.filedialog.askdirectory()
        self.select_path.set(path_)


def main():
    UIMAIN().create_UI()


if __name__ == "__main__":
    main()
